package com.isoft.c2team3service2.controller;

import com.isoft.c2team3service2.bean.ResponseData;
import com.isoft.c2team3service2.entity.Artist;
import com.isoft.c2team3service2.entity.ArtistEnumDTO;
import com.isoft.c2team3service2.service.ArtistService;
import com.isoft.c2team3service2.service.impl.BusinessException;
import com.isoft.c2team3service2.util.UserHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/artist")
public class ArtistController extends BaseController {

    @Autowired
    private ArtistService artistService;

    // 获取用户关注的艺人列表
    @GetMapping("/followed")
    public List<Artist> getFollowedArtists() {
        Integer userId = UserHolder.getUser().getId();
        return artistService.getArtistsByUserFollows(userId);
    }

    // 关注艺人
    @PostMapping("/follow/{artistId}")
    public ResponseData<Boolean> followArtist(@PathVariable Integer artistId) {
        try {
            boolean success = artistService.followArtist(artistId);
            return resultT(success, "关注");
        } catch (BusinessException e) {
            return resultT(false, e.getMessage());
        }
    }
    // 取消关注
    @DeleteMapping("/unfollow/{artistId}")
    public boolean unfollowArtist(@PathVariable Integer artistId) {
        return artistService.unfollowArtist(artistId);
    }

    //查询艺人列表
    @GetMapping("/list")
    public List<ArtistEnumDTO> searchArtists() {
        return artistService.searchArtists();
    }
}